package com.tich.enumration;

import lombok.Getter;

@Getter
public enum OrderStatus {
    UNPAID(1, "未支付"),
    CANCELLED(2, "已取消"),
    PAID(3, "已支付"),
    REFUNDED(4, "已退款");

    private final int code;
    private final String desc;

    OrderStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据状态码获取枚举实例
     * @param code 状态码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果无效状态码
     */
    public static OrderStatus getCode(int code) {
        for (OrderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的订单状态编码: " + code);
    }

    /**
     * 根据枚举实例获取中文描述
     * @param status 订单状态枚举
     * @return 对应的中文描述
     */
    public static String getChineseDesc(OrderStatus status) {
        return status.getDesc();
    }
}

